import { request } from 'umi';

/** 一级部门批量审批二级部门的库存申请 */
export async function batchRequestReview({ status, ids, remark }: { status: 'N' | 'D', ids: string[], remark: string }) {
  return request(`/api/inventory/batch/approval/${status}`, {
    method: 'PATCH',
    data: {
      approval_id_list: ids,
      approve_explain: remark
    },
    headers: { Action_Id: '200203010' }
  });
}

/** 一级部门审批二级部门的库存申请 */
export async function requestReview({ id, status, remark }: { id: string, status: 'N' | 'D', remark: string }, actionId: string) {
  return request(`/api/inventory/batch/approval/${id}/${status}`, {
    method: 'PATCH',
    data: {
      approve_explain: remark
    },
    headers: { Action_Id: actionId }
  });
}

/** 二级部门 */

/** 二级部门 商品管理 商品列表 */
export async function subGoodsList({ current, pageSize, ...data }: COMMON.PageParams & Partial<STOCKGOODSAPI.GoodsItem>) {
  return request<COMMON.PageResult<STOCKGOODSAPI.GoodsItem>>(`/api/inventory/goods/${current}/limit/${pageSize}`, {
    method: 'POST',
    data: data,
    headers: {
      Action_Id: '200200000'
    }
  });
}

/** 二级库存 商品下拉列表，一级也能用 */
export async function goodsListByPage({ current, pageSize, ...data }: Partial<COMMON.PageParams & STOCKGOODSAPI.GoodsItem>) {
  return request<COMMON.PageResult<STOCKGOODSAPI.GoodsItem>>(`/api/inventory/sub/goods/from/${current}/limit/${pageSize}`, {
    method: 'POST',
    data: data
  });
}

/** 二级库存 管理列表 */
export async function stockManageList({ current, pageSize, ...data }: COMMON.PageParams) {
  return request(`/api/inventory/sub/from/${current}/limit/${pageSize}`, {
    method: 'GET',
    params: data,
    headers: {
      Action_Id: '200204001'
    }
  });
}

/** 二级库存 申请记录列表 */
export async function stockRequestList(data: {
  begin_date?: string;
  end_date?: string;
  current?: number;
  pageSize?: number;
} & STOCKGOODSAPI.GoodsItem, actionId: string) {
  const { current, pageSize } = data;
  return request(`/api/inventory/batch/approval/from/${current}/limit/${pageSize}`, {
    method: 'GET',
    params: {
      ...data,
      batch_level: 2
    },
    headers: {
      Action_Id: actionId
    }
  });
}

/** 二级库存 下载申请记录列表 */
export async function stockRequestListDownload(data: STOCKGOODSAPI.GoodsItem & { begin_date?: string; end_date?: string; }, actionId: string) {
  return request(`/api/inventory/batch/approval/report`, {
    method: 'GET',
    params: data,
    headers: {
      Action_Id: actionId
    }
  });
}

/** 二级库存 申请入库 */
export async function stockRequestStorage({ specs_id, ...data }: any) {
  return request(`/api/inventory/batch/specs/${specs_id}`, {
    method: 'POST',
    data: data,
    headers: {
      Action_Id: '200204005'
    }
  });
}

/** 二级库存 申请退回 */
export async function stockRequestReturn({ specs_id, ...data }: any) {
  return request(`/api/inventory/batch/specs/${specs_id}`, {
    method: 'POST',
    data: data,
    headers: {
      Action_Id: '200204006'
    }
  });
}

/** 根据商品ID获取规格列表 */
export async function specListByGoodsId({ current, pageSize, goods_id, is_eng }: Partial<COMMON.PageParams & { goods_id: string, is_eng?: 'Y' }>) {
  return request<COMMON.PageResult<STOCKGOODSAPI.GoodsSpecsItem>>(`/api/inventory/goods/${goods_id}/specs/${current}/limit/${pageSize}`, {
    params: { is_eng }
  });
}


/** 查询二级库存规格 */
export async function getSubGoodsSpecsList(params: { current?: number; pageSize?: number; goods_id?: string; goods_dept_code?: string; }) {
  const { current, pageSize, goods_id, goods_dept_code } = params;
  return request(`/api/inventory/sub/goods/${goods_id}/specs/${current}/limit/${pageSize}?goods_dept_code=${goods_dept_code || ''}`, {
    method: 'GET'
  });
}
